#include "Globals.h"
#include <sstream>

thor::FrameAnimation::Ptr explosion(new thor::FrameAnimation);
sf::Font font;

int side = 0;

//std::mt19937 rng;

int points = 0;
int lives = 3;
int killedBricks = 0;
int currentState = 1;
int pauseCount = 0;

long tNormalBricks = 0;
long tExploBricks = 0;
long tGreenBricks = 0;
long tMiniBricks = 0;
long tPinBricks = 0;
long tSmallerPanelBonuses = 0;
long tBiggerPanelBonuses = 0;
long tLiveBonuses = 0;
long tPauseBonuses = 0;
long tAcidBonuses = 0;
long tBallBonuses = 0;
long tLivesLost = 0;
long tGameOver = 0;
long tBestScore = 0;

bool dead = false;
bool Pause = false;

std::string to_string(int number)
{
   std::stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
void setCenter(sf::Text& txt, int y)
{
    sf::FloatRect rect = txt.GetGlobalBounds();
    txt.SetPosition((WIDTH+200)/2 - rect.Width/2 , y);
}

bool collide(sf::Sprite s1, sf::Sprite s2)
{
    float x1 = s1.GetGlobalBounds().Left;
    float y1 = s1.GetGlobalBounds().Top;
    float x2 = s2.GetGlobalBounds().Left;
    float y2 = s2.GetGlobalBounds().Top;

    float l1 = s1.GetGlobalBounds().Height;
    float w1 = s1.GetGlobalBounds().Width;
    float l2 = s2.GetGlobalBounds().Height;
    float w2 = s2.GetGlobalBounds().Width;

    if(y1 + l1 > y2 && y2 + l2 > y1) //between horizontal lines
    {
        if(x1 > x2) //s1 is right of s2
        {
            if(x1 - 5 < x2 + w2)
            {
                side = 1;
                return true;
            }
        }
        else        //s1 is left of s2
        {
            if(x2 - 5 < x1 + w1)
            {
                side = 3;
                return true;
            }
        }
    }

    if(x1 + w1 > x2 && x1 < x2 + w2) //vertical lines
    {
        if(y1 < y2) //s1 is above s2
        {
            if(y1 + l1 > y2 - 7)
            {
                side = 0;
                return true;
            }
        }
        else        //s1 is under s2
        {
            if(y2 + l2 > y1 - 7)
            {
                side = 2;
                return true;
            }
        }
    }



    return false;
}

float abso(float i)
{
    if(i < 0)
    return -i;
    else
    return i;
}
